import request from '@/utils/http'
import type { BaseResult, PageParams, PageResult } from '@/types/axios.d'
import type { CommodityType } from '@/api/model/commodityModel'

// 商品管理查询
export function getCommodityList(
  data: PageParams & {
    productName?: string
    classifyId?: number
    state?: number
  }
): Promise<BaseResult<PageResult<CommodityType>>> {
  return request.post({
    url: '/canvas/getAll',
    data
  })
}

// 商品详情查询
export function getCommodityById(data: { productId: number }): Promise<BaseResult<CommodityType>> {
  return request.post({
    url: '/canvas/getById',
    data
  })
}

// 商品上下架
export function toggleCommodityStatus(data: {
  productId: number
  state: number
}): Promise<BaseResult<null>> {
  return request.post({
    url: '/product/start',
    data
  })
}

// 强制下架
export function forceOffShelf(data: { productId: number }): Promise<BaseResult<null>> {
  return request.post({
    url: '/canvas/forced',
    data
  })
}

// 商品审核
export function examineCommodity(data: {
  productId: number
  state: number
  reason?: string
}): Promise<BaseResult<null>> {
  return request.post({
    url: '/canvas/examine',
    data
  })
}

// 删除商品
export function deleteCommodity(data: { productId: number }): Promise<BaseResult<null>> {
  return request.post({
    url: '/product/delete',
    data
  })
}

// 导出商品
export function exportCommodity(
  data: PageParams & {
    productName?: string
    classifyId?: number
    state?: number
  }
): Promise<any> {
  return request.post({
    url: '/canvas/exportAll',
    data,
    responseType: 'blob'
  })
}

// 设置虚拟销量
export function setFictitious(data: {
  productId: number
  fictitiousNumber: number
}): Promise<BaseResult<null>> {
  return request.post({
    url: '/canvas/setFictitious',
    data
  })
}
